//=============================================================================

#include "../inc/aAction.h"

//=============================================================================

aAction::aAction() : type(ACT_NONE), dataPtr(0)
{
}

//=============================================================================

void aAction::aaPrepareAction(const aActionChoosed& act)
{
  aActionChoosed* tmpAction = new aActionChoosed;

  tmpAction->params = act.params;
  type = tmpAction->type;

  dataPtr = (void*)tmpAction;
}

//=============================================================================

void aAction::aaPrepareAction(const aActionWalk& act)
{
  aActionWalk* tmpAction = new aActionWalk;
  aItem<aVector>* tmpVector = act.path.alGetFirstItem();

  while(tmpVector)
  {
    tmpAction->path.alAddItem()->data = tmpVector->data;
    tmpVector = tmpVector->next;
  }

  type = tmpAction->type;

  dataPtr = (void*)tmpAction;
}

//=============================================================================

void aAction::aaPrepareAction(const aActionAttack& act)
{
  aActionAttack* tmpAction = new aActionAttack;

  type = tmpAction->type;

  dataPtr = (void*)tmpAction;
}

//=============================================================================

void aAction::aaClearAction()
{
  if (dataPtr)
  {
    switch(type)
    {
      case ACT_CHOOSED:
      {
        delete (aActionChoosed*)dataPtr;

        dataPtr = 0;

        break;
      }
      case ACT_WALK:
      {
        delete (aActionWalk*)dataPtr;

        dataPtr = 0;

        break;
      }
      case ACT_ATTACK:
      {
        delete (aActionAttack*)dataPtr;

        dataPtr = 0;

        break;
      }
      default:
      {
        break;
      }
    }
  }
}

//=============================================================================

aAction::~aAction()
{
  aaClearAction();
}

//=============================================================================
